#include "Http.hpp"

void Login(HttpRequest &req, HttpResponse &resp)
{
    LOG(Loglevel::DEBUG) << req.Args() << ", 我们成功进入到了处理数据的逻辑";
    std::string text = "hello " + req.Args();

    resp.SetCode(200);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
    resp.SetText(text);
}

void Register(HttpRequest &req, HttpResponse &resp)
{
    LOG(Loglevel::DEBUG) << req.Args() << ", 我们成功进入到了处理数据的逻辑";
    std::string text = "hello " + req.Args();

    resp.SetCode(200);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
    resp.SetText(text);
}

void VipCheck(HttpRequest &req, HttpResponse &resp)
{
    LOG(Loglevel::DEBUG) << req.Args() << ", 我们成功进入到了处理数据的逻辑";
    std::string text = "hello " + req.Args();
    
    resp.SetCode(200);
    resp.SetHeader("Content-Type", "text/plain");
    resp.SetHeader("Content-Length", std::to_string(text.size()));
    resp.SetText(text);
}

// http port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        exit(USAGE_ERROR);
    }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<Http> httpser = std::make_unique<Http>(port);
    httpser->RegisterServer("/login",Login);
    httpser->RegisterServer("/register",Register);
    httpser->RegisterServer("/vip_check",VipCheck);
    httpser->Start();
    return 0;
}